<?php session_start(); ?>
<?php 
  include "tab.php";
  	/* update*/
 					    $yearb=$_REQUEST[yearb];
						$termb=$_REQUEST[termb];
						
						$idB=$_REQUEST[idB];	
						$submitUP=$_REQUEST[submitUP];	
						if($submitUP=="แก้ไข")
						{
						$sql="	UPDATE  health_base
							SET		
								study_year='$yearb',
								term='$termb'
								
							WHERE	base_id='$idB'
							LIMIT	1	";
						$result=@mysql_db_query($dbname,$sql);
			mysql_close();
			$submitUP=="";
			echo "<script>window.location='?option=health&task=admin_year'; </script>";
			}
			
/*ADD Data*/
	$submitAD=$_REQUEST[submitAD];	
			if($submitAD=="บันทึก")
			{
				$sql="INSERT INTO health_base VALUES('','$yearb','$termb','0')";
												$result=@mysql_db_query($dbname,$sql);	
												mysql_close();
			$submitAD=="";
			echo "<script>window.location='?option=health&task=admin_year'; </script>";
				}
		
		/*Delete Data*/
			$show=$_REQUEST[show];	
		if($show==1)
		{
				$sql="DELETE FROM health_base WHERE base_id='$idB'";
							$result=@mysql_db_query($dbname,$sql);		
							mysql_close();
							echo "<script>window.location='?option=health&task=admin_year'; </script>";
			}
					$checkU=$_REQUEST[checkU];	
			if($checkU=="U")
			{
				/* set 0 all*/
				$sqlU="	UPDATE  health_base
							SET		
								status='0'								
							WHERE	base_id
							";
						$resultU=@mysql_db_query($dbname,$sqlU);
					/*set 1*/	
							$sqlU2="	UPDATE  health_base
							SET		
								status='1'
								
							WHERE	base_id='$idB'
							LIMIT	1	";
						$resultU2=@mysql_db_query($dbname,$sqlU2);
				}
?>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>ข้อมูลพื้นฐาน</title>
<link rel='stylesheet' href='modules/health/css_health.css'>
</head>
<script>
function checkfof(form1){
	
					if (form1.yearb.value == ""){
				alert('กรอก ปีการศึกษา');
					return false;}
					
					if (form1.termb.value == ""){
				alert('กรอก ภาคเรียน');
					return false;}
			}
</script>
<body topmargin="0" bgcolor="#F4FFF4">
<br>

<?
if($show==3){
?>
    <form id="form1" name="form1" method="post" action="?option=health&task=admin_year" enctype="multipart/form-data" onSubmit="return checkfof(this)">
    <table  border="1" align="center" cellpadding="0" cellspacing="0" bordercolor="#99CCFF" bgcolor="#FFFFFF">
    <tr><td>
      <table width="500"  border="0" align="center" cellpadding="" cellspacing="">
  <tr>
    <td height="30" align="left" bgcolor="#0066FF" class="topbg"><?=$t2?>
     <font color="#FFFFFF">  เพิ่มข้อมูลพื้นฐาน</font></td>
  </tr>
  <tr>
    <td align="center" valign="top">

    <table width="204" border="0" align="center" cellpadding="0" cellspacing="0">
      <tr>
        <td colspan="2" align="center">&nbsp;</td>
      </tr>
      <tr>
        <td width="114" valign="middle">ปีการศึกษา :</td>
        <td width="90" align="left" valign="middle"><input name="yearb" type="text" id="yearb" size="4" maxlength="4" />        </td>
        </tr>
      <tr>
        <td valign="middle">ภาคเรียนที่ :</td>
        <td align="left" valign="middle"><input name="termb" type="text" id="termb" size="2" maxlength="2" />        </td>
        </tr>
      <tr>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        </tr>
      <tr>
        <td align="right"><input type="submit" name="submitAD"  value="บันทึก"></td>
        <td><input type="reset" name="ResetAD" id="button" value="ยกเลิก"></td>
        </tr>
    </table>
      <br></td>
  </tr>
</table>
</td></tr></table>
</form>
<? }?>
<?
/*  update */
if($show==2){
?>
    <form id="form1" name="form1" method="post" action="?option=health&task=admin_year" enctype="multipart/form-data" onSubmit="return checkfof(this)">   
     <table  border="1" align="center" cellpadding="0" cellspacing="0" bordercolor="#99CCFF" bgcolor="#FFFFFF">
    <tr><td>
      <table width="500"  border="0" align="center" cellpadding="" cellspacing="">
  <tr>
    <td height="30" align="left" bgcolor="#0066FF" class="topbg"><?=$t2?>
     <font color="#FFFFFF">  แก้ไขข้อมูลพื้นฐาน</font></td>
  </tr>
  <tr>
    <td align="center" valign="top" >
    <?
       $sqlB="SELECT* FROM health_base WHERE base_id='$idB'";
		   		$resultB=@mysql_db_query($dbname,$sqlB); 
		   		$recordB=@mysql_fetch_array($resultB);
	?>
    <table width="204" border="0" align="center" cellpadding="0" cellspacing="0">

      <tr>
        <td colspan="2" align="center">&nbsp;</td>
      </tr>
      <tr>
        <td width="114" valign="middle">ปีการศึกษา :</td>
        <td width="90" align="left" valign="middle"><input name="yearb" type="text" id="yearb" size="4" maxlength="4" value="<?=$recordB[1]?>" />        </td>
        </tr>
      <tr>
        <td valign="middle">ภาคเรียนที่ :</td>
        <td align="left" valign="middle"><input name="termb" type="text" id="termb" size="2" maxlength="2" value="<?=$recordB[2]?>" />        </td>
        </tr>
      <tr>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        </tr>
      <tr>
        <td align="right"><input type="submit" name="submitUP"  value="แก้ไข">
        <input type="hidden" name="idB" value="<?=$recordB[0]?>">
        </td>
        <td><input type="reset" name="ResetUP" id="button" value="ยกเลิก"></td>
        </tr>
    </table>
      <br></td>
  </tr>
</table>
</td></tr></table>
</form>
<? }?>
<?
				 $sqlS="SELECT* FROM health_base order by base_id desc";
		   		$resultS=@mysql_db_query($dbname,$sqlS); 
		   		
?>
<table width="500" border="0" align="center">
  <tr align="center" valign="middle" >
    <td width="54"><? if($show!=3) { ?><input type="button" value=" เพิ่ม " name="add" onclick='location.href="?option=health&show=3&task=admin_year"'> <? }?></td>
    <td width="109">&nbsp;</td>
    <td width="99">&nbsp;</td>
    <td width="126">&nbsp;</td>
    <td width="90">&nbsp;</td>
  </tr>
  <tr align="center" valign="middle" >
    <td width="54" bgcolor="#76CEEB" class="topbg">ลำดับ</td>
    <td width="109" bgcolor="#76CEEB" class="topbg">ปีการศึกษา</td>
    <td width="99" bgcolor="#76CEEB" class="topbg">ภาคเรียน</td>
    <td width="126" bgcolor="#76CEEB" class="topbg">สถานะใช้งาน</td>
    <td width="90" bgcolor="#76CEEB" class="topbg">จัดการ</td>
  </tr>
  <?
 		 $Bnum=1;
		  while($recordS=@mysql_fetch_array($resultS)){
			
				$c1="#DDF4F9";
			 	$c2="#FEE2FC";
				if($bg==$c1){
				$bg=$c2;
				}else{
				$bg=$c1;
				}
  ?>
  <tr bgcolor="<?=$bg?>">
    <td align="center"><?=$Bnum?></td>
    <td align="center"><?=$recordS[1]?></td>
    <td align="center"><?=$recordS[2]?></td>
    <td align="center"><? if($recordS[3]==1)
	{
	echo"	<a href='?option=health&task=admin_year&idB=$recordS[0]&checkU=U'><img src='modules/health/iconH/yes.png' border='0'></a>";
		}else{
		echo"	<a href='?option=health&task=admin_year&idB=$recordS[0]&checkU=U'><img src='modules/health/iconH/no.png' border='0'></a>";
		}
	?></td>
    <td align="center"><? if($recordS[3]==1) { print'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';}else {?>[<a href="?option=health&task=admin_year&stcbase=del&idB=<?=$recordS[0]?>&show=1" onClick="return confirm('คุณต้องการจะลบ ปีการศึกษา <?=$recordS[1]?> ภาคเรียนที่  <?=$recordS[2]?> ')">ลบ</a>]<? }?> [<a href="?option=health&task=admin_year&stcbase=up&idB=<?=$recordS[0]?>&show=2">แก้ไข</a>]</td>
  </tr>
  <? 
  $Bnum++;
		  }
  ?>
</table>

</body>
</html>
